package gov.pbc.gx.nn.pz.impl;

import gov.pbc.gx.nn.pz.dao.ZhglxxDao;
import gov.pbc.gx.nn.pz.entity.Account;
import gov.pbc.gx.nn.pz.entity.HcBwpz;
import gov.pbc.gx.nn.pz.entity.HcXjpz;
import gov.pbc.gx.nn.pz.entity.HcZhglxx;
import gov.pbc.gx.nn.pz.entity.HcpzXY;
import gov.pbc.gx.nn.pz.entity.PzFont;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.imageio.ImageIO;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.exception.NoneLoginException;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.variant.Record;
import com.bstek.dorado.web.DoradoContext;

/**
 * 
 * @author jack.zhao 本类主要实现zhglxx业务逻辑的操作
 * 
 */

@Component("zhglxxPR")
public class ZhglxxPR {

	private static final Integer PZ_CODE_ = 11;
	private static final Integer Font_Size = 16;
	@Resource
	@Autowired
	private ZhglxxDao zhglxxDao;

	@Transactional
	@DataProvider
	public Record getzhglxxs() {
		try {
			IUser loginuser = ContextHolder.getLoginUser();
			if (loginuser == null)
				return null;
			if (loginuser.getDepts() == null || loginuser.getDepts().size() <= 0)
				return null;
			Record record = new Record();
			record.put("pzdate", new Date());
			ArrayList<HcZhglxx> lists = (ArrayList<HcZhglxx>) zhglxxDao.getMuByDeptName();
			if (lists.isEmpty()) {
				HcZhglxx e = new HcZhglxx();
				e.setPzDate(new Date());
				e.setPzTemplate("新建模板");
//				e.setCurrency("1");
				lists.add(e);
				record.put("zhglxx", lists);
			} else {
				lists.get(0).setPzDate(new Date());
				record.put("zhglxx", lists);
			}

			List<HcpzXY> xjpzXYs = zhglxxDao.getHcPzXYs(PZ_CODE_);
			if (xjpzXYs != null && !xjpzXYs.isEmpty()) {
				record.put("pys", xjpzXYs);
			} else {

				xjpzXYs = new ArrayList<HcpzXY>();
				HcpzXY xjpzXY = new HcpzXY();
				xjpzXY.setProperty("页边距", 50, 50, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setId(UUID.randomUUID().toString());
				xjpzXY.setProperty("年", 270, 91, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("月", 350, 91, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("日", 420, 91, Font_Size);
				xjpzXYs.add(xjpzXY);

				// xjpzXY = new HcpzXY();
				// xjpzXY.setProperty("流水号", 560, 70);
				// xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("帐号", 140, 125, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("账户名称", 140, 183, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("请选择业务种类", 180, 150, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("简称1", 180, 213, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("简称2", 490, 213, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("简称3", 180, 243, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("简称4", 490, 243, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("开户单位全称", 265, 273, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("开户单位地址", 265, 303, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("帐号用途", 265, 333, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("组织结构代码", 265, 363, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("营业执照号码", 570, 363, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("金融许可号码", 265, 393, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("税务登记证号码", 570, 393, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("单位负责人名称", 265, 423, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("联系人姓名", 570, 423, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("单位负责人证件名称", 265, 453, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("单位负责人证件号码", 570, 453, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("邮政编码", 265, 483, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("联系电话", 570, 483, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("币种", 265, 513, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("币种其他", 580, 510, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("系统内帐号", 265, 543, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("系统外帐号", 265, 573, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("金融机构代码", 460, 603, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("上级法人帐号", 460, 633, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("是否使用支付密码", 280, 663, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("对账标志", 280, 693, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("回单标志", 280, 723, Font_Size);
				xjpzXYs.add(xjpzXY);

				xjpzXY = new HcpzXY();
				xjpzXY.setProperty("账户注销理由", 140, 758, Font_Size);
				xjpzXYs.add(xjpzXY);

			}

			record.put("pys", xjpzXYs);
			return record;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	private void setImageData(Graphics2D graphics, Map<String, Object> param) {
		try {
			HcZhglxx hcZhglxx = (HcZhglxx) param.get("zhglxx");

			Date pzdate = (Date) param.get("pzdate");
			int pyx = (int) Integer.parseInt(param.get("x").toString());
			int pyy = (int) Integer.parseInt(param.get("y").toString());
			String fontzh = param.get("fontzh").toString();
			String fonten = param.get("fonten").toString();
			String click = "√";

			graphics.setBackground(Color.WHITE);
			graphics.setColor(Color.BLACK);
			// Font zhFont = new Font(fontzh, Font.PLAIN, 16);
			// Font enFont = new Font(fonten, Font.PLAIN, 16);
			List<HcpzXY> hcpzxys = (List<HcpzXY>) param.get("pys");
			for (HcpzXY pym : hcpzxys) {
				int fontSize = pym.getFontSize();
				Font zhFont = new Font(fontzh, Font.PLAIN, fontSize);
				Font enFont = new Font(fonten, Font.PLAIN, fontSize);
				graphics.setFont(zhFont);
				int x = pym.getX() + pyx;
				int y = pym.getY() + pyy;
				int tzx = -2;
				int tzy = -3;
				String lable = pym.getLabel();
				if (pzdate != null) {
					graphics.setFont(enFont);
					Calendar calendar = Calendar.getInstance();
					calendar.setTime(pzdate);
					if (lable.equals("年")) {
						graphics.drawString(String.format("%04d", calendar.get(Calendar.YEAR)), x, y);
					}
					if (lable.equals("月")) {
						graphics.drawString(String.format("%02d", calendar.get(Calendar.MONTH) + 1), x, y);
					}
					if (lable.equals("日")) {
						graphics.drawString(String.format("%02d", calendar.get(Calendar.DATE)), x, y);
					}

				}
				if (hcZhglxx != null) {
					// if (lable.equals("流水号")) {
					// if (hcZhglxx.getSerialnumber() != null) {
					// graphics.setFont(enFont);
					// graphics.drawString(hcZhglxx.getSerialnumber(), x,
					// y);
					// }
					// }

					if (lable.equals("帐号")) {
						if (hcZhglxx.getCompanyAccount() != null) {
							graphics.setFont(enFont);
							graphics.drawString(hcZhglxx.getCompanyAccount(), x, y + tzy - 2);
						}
					}

					if (lable.equals("账户名称")) {
						if (hcZhglxx.getCompanyName() != null) {
							graphics.drawString(hcZhglxx.getCompanyName(), x, y + tzy);
						}
					}

					if (lable.equals("请选择业务种类")) {
						if (hcZhglxx.getQxzywzlType() != null) {
							if (Integer.valueOf(hcZhglxx.getQxzywzlType()) == 1) {
								graphics.drawString(click, x - 2, y);
							}
							if (Integer.valueOf(hcZhglxx.getQxzywzlType()) == 2) {
								graphics.drawString(click, 115 + x - 2, y);
							}
							if (Integer.valueOf(hcZhglxx.getQxzywzlType()) == 3) {
								graphics.drawString(click, 228 + x - 2, y);
							}
						}
					}

					if (lable.equals("简称1")) {
						if (hcZhglxx.getJcOne() != null) {
							graphics.drawString(hcZhglxx.getJcOne(), x, y - 1);
						}
					}

					if (lable.equals("简称2")) {
						if (hcZhglxx.getJcTwo() != null) {
							graphics.drawString(hcZhglxx.getJcTwo(), x, y - 1);
						}
					}

					if (lable.equals("简称3")) {
						if (hcZhglxx.getJcThree() != null) {
							graphics.drawString(hcZhglxx.getJcThree(), x, y - 1);
						}
					}

					if (lable.equals("简称4")) {
						if (hcZhglxx.getJcFour() != null) {
							graphics.drawString(hcZhglxx.getJcFour(), x, y - 1);
						}
					}

					if (lable.equals("开户单位全称")) {
						if (hcZhglxx.getKhdwName() != null) {
							graphics.drawString(hcZhglxx.getKhdwName(), x, y);
						}
					}

					if (lable.equals("开户单位地址")) {
						if (hcZhglxx.getKhdwAddress() != null) {
							graphics.drawString(hcZhglxx.getKhdwAddress(), x, y);
						}
					}

					if (lable.equals("帐号用途")) {
						if (hcZhglxx.getZhUse() != null) {
							graphics.drawString(hcZhglxx.getZhUse(), x, y);
						}
					}

					if (lable.equals("组织结构代码")) {
						if (hcZhglxx.getZzjgCode() != null) {
							graphics.drawString(hcZhglxx.getZzjgCode(), x, y);
						}
					}

					if (lable.equals("营业执照号码")) {
						if (hcZhglxx.getYyzzNumber() != null) {
							graphics.drawString(hcZhglxx.getYyzzNumber(), x, y);
						}
					}

					if (lable.equals("金融许可号码")) {
						if (hcZhglxx.getJrxkNumber() != null) {
							graphics.drawString(hcZhglxx.getJrxkNumber(), x, y);
						}
					}

					if (lable.equals("税务登记证号码")) {
						if (hcZhglxx.getSwdjzNumber() != null) {
							graphics.drawString(hcZhglxx.getSwdjzNumber(), x, y);
						}
					}

					if (lable.equals("单位负责人名称")) {
						if (hcZhglxx.getDwfzrName() != null) {
							graphics.drawString(hcZhglxx.getDwfzrName(), x, y);
						}
					}

					if (lable.equals("联系人姓名")) {
						if (hcZhglxx.getLxrName() != null) {
							graphics.drawString(hcZhglxx.getLxrName(), x, y);
						}
					}

					if (lable.equals("单位负责人证件名称")) {
						if (hcZhglxx.getDwfzrzjName() != null) {
							graphics.drawString(hcZhglxx.getDwfzrzjName(), x, y);
						}
					}

					if (lable.equals("单位负责人证件号码")) {
						if (hcZhglxx.getDwfzrzjNumber() != null) {
							graphics.drawString(hcZhglxx.getDwfzrzjNumber(), x, y);
						}
					}

					if (lable.equals("邮政编码")) {
						if (hcZhglxx.getPostCode() != null) {
							graphics.drawString(hcZhglxx.getPostCode(), x, y);
						}
					}

					if (lable.equals("联系电话")) {
						if (hcZhglxx.getContactNumber() != null) {
							graphics.drawString(hcZhglxx.getContactNumber(), x, y);
						}
					}

					if (lable.equals("币种")) {
						if (hcZhglxx.getCurrency() != null) {
							if (Integer.valueOf(hcZhglxx.getCurrency()) == 1) {
								graphics.drawString(click, x - 2, y);
							}
							if (Integer.valueOf(hcZhglxx.getCurrency()) == 2) {
								graphics.drawString(click, 87 + x - 2, y);
							}
							if (Integer.valueOf(hcZhglxx.getCurrency()) == 3) {
								graphics.drawString(click, 175 + x - 2, y);
							}
							if (Integer.valueOf(hcZhglxx.getCurrency()) == 4) {
								graphics.drawString(click, 255 + x - 2, y);
							}
						}
					}

					if (lable.equals("币种其他")) {
						if (hcZhglxx.getCurrencyOther() != null) {
							graphics.drawString(hcZhglxx.getCurrencyOther(), x, y);
						}
					}
					if (lable.equals("系统内帐号")) {
						if (hcZhglxx.getSystemInNumber() != null) {
							if (Integer.valueOf(hcZhglxx.getSystemInNumber()) == 1) {
								graphics.drawString(click, x - 2, y + 1);
							}
							if (Integer.valueOf(hcZhglxx.getSystemInNumber()) == 2) {
								graphics.drawString(click, 87 + x - 2, y + 1);
							}
							if (Integer.valueOf(hcZhglxx.getSystemInNumber()) == 3) {
								graphics.drawString(click, 175 + x - 2, y + 1);
							}
							if (Integer.valueOf(hcZhglxx.getSystemInNumber()) == 4) {
								graphics.drawString(click, 255 + x - 2, y + 1);
							}
							if (Integer.valueOf(hcZhglxx.getSystemInNumber()) == 5) {
								graphics.drawString(click, 335 + x - 2, y + 1);
							}
							if (Integer.valueOf(hcZhglxx.getSystemInNumber()) == 6) {
								graphics.drawString(click, 418 + x - 2, y + 1);
							}
						}
					}

					if (lable.equals("系统外帐号")) {
						if (hcZhglxx.getSystemOutNumber() != null) {
							if (Integer.valueOf(hcZhglxx.getSystemOutNumber()) == 1) {
								graphics.drawString(click, x - 2, y + 2);
							}
							if (Integer.valueOf(hcZhglxx.getSystemOutNumber()) == 2) {
								graphics.drawString(click, 87 + x - 2, y + 2);
							}
							if (Integer.valueOf(hcZhglxx.getSystemOutNumber()) == 3) {
								graphics.drawString(click, 175 + x - 2, y + 2);
							}
						}
					}

					if (lable.equals("金融机构代码")) {
						if (hcZhglxx.getJrjgCode() != null) {
							graphics.setFont(enFont);
							graphics.drawString(hcZhglxx.getJrjgCode(), x, y);
						}
					}

					if (lable.equals("上级法人帐号")) {
						if (hcZhglxx.getSjfrAccount() != null) {
							graphics.setFont(enFont);
							graphics.drawString(hcZhglxx.getSjfrAccount(), x, y);
						}
					}

					if (lable.equals("是否使用支付密码")) {
						if (hcZhglxx.getUsePassword() != null) {
							if (Integer.valueOf(hcZhglxx.getUsePassword()) == 1) {
								graphics.drawString(click, 73 + x - 2, y + 3);
							}
							if (Integer.valueOf(hcZhglxx.getUsePassword()) == 2) {
								graphics.drawString(click, 147 + x - 2, y + 3);
							}
						}
					}

					if (lable.equals("对账标志")) {
						if (hcZhglxx.getDzMark() != null) {
							if (Integer.valueOf(hcZhglxx.getDzMark()) == 1) {
								graphics.drawString(click, 73 + x - 2, y + 3);
							}
							if (Integer.valueOf(hcZhglxx.getDzMark()) == 2) {
								graphics.drawString(click, 147 + x - 2, y + 3);
							}
							if (Integer.valueOf(hcZhglxx.getDzMark()) == 3) {
								graphics.drawString(click, 220 + x - 2, y + 3);
							}
						}
					}

					if (lable.equals("回单标志")) {
						if (hcZhglxx.getHdMark() != null) {
							if (Integer.valueOf(hcZhglxx.getHdMark()) == 1) {
								graphics.drawString(click, 73 + x - 2, y + 3);
							}
							if (Integer.valueOf(hcZhglxx.getHdMark()) == 2) {
								graphics.drawString(click, 147 + x - 2, y + 3);
							}
							if (Integer.valueOf(hcZhglxx.getHdMark()) == 3) {
								graphics.drawString(click, 220 + x - 2, y + 3);
							}
						}
					}

					if (lable.equals("账户注销理由")) {
						if (hcZhglxx.getCancelReason() != null) {
							graphics.drawString(hcZhglxx.getCancelReason(), x, y);
						}
					}

				}

			}

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	@Expose
	public String getPrintImageAll(Map<String, Object> param) {
		try {
			if (param == null)
				return null;
			IUser loginuser = ContextHolder.getLoginUser();
			if (loginuser == null)
				throw new NoneLoginException("您未登录，请刷新页面后重试！！");
			// param.put("x", -25);
			// param.put("y", -29);
			BufferedImage imagepz = ImageIO.read(new File(DoradoContext.getCurrent().getServletContext().getRealPath("pz/xjpz.png")));
			Graphics2D graphicspz = (Graphics2D) imagepz.getGraphics();

			setImageData(graphicspz, param);
			// ByteArrayOutputStream bytestreampz=new ByteArrayOutputStream();
			String filename = "pz/temp/all_" + loginuser.getUsername() + ".png";
			FileOutputStream fo = new FileOutputStream(new File(DoradoContext.getCurrent().getServletContext().getRealPath(filename)));
			ImageIO.write(imagepz, "png", fo);
			fo.flush();
			fo.close();
			// String
			// str="data:image/png;base64,"+Base64.encodeBase64String(bytestreampz.toByteArray());
			// System.out.println(str.length()+","+bytestreampz.toByteArray().length);
			return filename;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Expose
	public String getPrintImageData(Map<String, Object> param) {
		try {
			if (param == null)
				return null;
			IUser loginuser = ContextHolder.getLoginUser();
			if (loginuser == null)
				throw new NoneLoginException("您未登录，请刷新页面后重试！！");
			param.put("x", -33);
			param.put("y", -32);
			// 37
			// 34
			BufferedImage imagedata = ImageIO.read(new File(DoradoContext.getCurrent().getServletContext().getRealPath("pz/zhglxx.jpg")));
			// System.out.println(imagepz.getWidth()*1.0/96.0*24.5);
			// BufferedImage imagedata= new BufferedImage(imagepz.getWidth(),
			// imagepz.getHeight(), imagepz.getType());
			Graphics2D graphicsdata = (Graphics2D) imagedata.getGraphics();
			graphicsdata.setBackground(Color.WHITE);

			// 打印背景图片
			graphicsdata.clearRect(0, 0, imagedata.getWidth(), imagedata.getHeight());
			setImageData(graphicsdata, param);
			// ByteArrayOutputStream bytestreampz=new ByteArrayOutputStream();
			String filename = "pz/temp/data_" + loginuser.getUsername() + ".jpg";
			FileOutputStream fo = new FileOutputStream(new File(DoradoContext.getCurrent().getServletContext().getRealPath(filename)));
			ImageIO.write(imagedata, "jpg", fo);
			fo.flush();
			fo.close();
			// String
			// str="data:image/png;base64,"+Base64.encodeBase64String(bytestreampz.toByteArray());
			// System.out.println(str.length()+","+bytestreampz.toByteArray().length);
			return filename;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Expose
	public Map<String, Object> getUserInfo() {
		IUser loginuser = ContextHolder.getLoginUser();
		Map<String, Object> userinfo = new HashMap<String, Object>();
		if (loginuser == null) {
			userinfo.put("cname", "");
			userinfo.put("dept", "");
			return userinfo;
		}
		userinfo.put("cname", loginuser.getCname());
		if (loginuser.getDepts() == null || loginuser.getDepts().size() <= 0) {
			userinfo.put("dept", "");
			return userinfo;
		}
		userinfo.put("dept", loginuser.getDepts().get(0).getName());
		return userinfo;
	}

	@DataProvider
	public Collection<HcZhglxx> getTypeByGroup() {
		
		ArrayList<HcZhglxx> xjpzs = new ArrayList<HcZhglxx>();
		xjpzs = (ArrayList<HcZhglxx>) zhglxxDao.getOneGroupByType();
		for (int i = 0; i < xjpzs.size(); i++) {
			xjpzs.get(i).setPzDate(new Date());
		}
		return xjpzs;
		
		
//		return zhglxxDao.getOneGroupByType();

	}

	@DataProvider
	public Collection<HcZhglxx> getTepementNameByType(Map<String, Object> param) {
		if (param == null) {
			return null;
		}
		String type = (String) param.get("type");
		
		
		
		ArrayList<HcZhglxx> xjpzs = new ArrayList<HcZhglxx>();
		xjpzs = (ArrayList<HcZhglxx>) zhglxxDao.getCoByType(type);
		for (int i = 0; i < xjpzs.size(); i++) {
			xjpzs.get(i).setPzDate(new Date());
		}
		return xjpzs;
		
//		return zhglxxDao.getCoByType(type);
	}

	@Expose
	public HcZhglxx ajaxselectOneByTypeAndTemplate(Map<String, Object> param) {
		String type = (String) param.get("type");
		String pztemplate = (String) param.get("pzTemplate");
		if (type == null || pztemplate == null) {
			return null;
		}
		HcZhglxx pz=zhglxxDao.selectOneByTypeAndTemplate(type, pztemplate);
		pz.setPzDate(new Date());
		return pz;
		
		
//		return zhglxxDao.selectOneByTypeAndTemplate(type, pztemplate);

	}

	@DataProvider
	public List<Record> getFonts() {
		return zhglxxDao.getFonts();
	}

	@DataProvider
	public PzFont getFont() {
		return zhglxxDao.getFont(PZ_CODE_);
	}

	// 名字需要做修改！
	@Transactional
	@DataResolver
	public void saveZhglxx(HcZhglxx hczhglxx) {
		zhglxxDao.saveZhglxx(hczhglxx);
	}

	@Transactional
	@DataResolver
	public void savepzXY(Collection<HcpzXY> hcpzxys) {
		zhglxxDao.saveXjpzXY(hcpzxys);

	}

	@Transactional
	@DataResolver
	public void saveFont(PzFont pzFont) throws Exception {
		zhglxxDao.updateFont(pzFont);
	}

	@Expose
	public void deleteTemplateById(String id) {
		if (StringUtils.isEmpty(id)) {
			return;
		}
		zhglxxDao.deleteTemplateById(id);
	}

	@Expose
	public Account ajaxActionGetName(Map<String, Object> parameter) {
		String account = (String) parameter.get("account");
		return zhglxxDao.getAccountName(account);

	}
	@Expose
	public boolean updateTempalteName(Map<String, Object> parameter) {
		String id = (String) parameter.get("id");
		String pzTemplate = (String) parameter.get("pzTemplate");
		return zhglxxDao.updateTemplateNameDao(pzTemplate, id);
	}

	@Expose
	public boolean updateTempalteType(Map<String, Object> parameter) {
		String id = (String) parameter.get("id");
		String type = (String) parameter.get("type");
		return zhglxxDao.updateTemplateTypeDao(type, id);
	}
}
